VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmVentasCaidasCobros 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   5  'Sizable ToolWindow
   Caption         =   "Ventas Caidas / Departamento de Cobros"
   ClientHeight    =   8040
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11340
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Moveable        =   0   'False
   ScaleHeight     =   8040
   ScaleWidth      =   11340
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdOrdenarUnidad 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Ordenar por Unidad"
      Height          =   312
      Left            =   5880
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   7560
      Width           =   1692
   End
   Begin VB.CommandButton cmdOrdenarRuta 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Ordenar por Ruta"
      Height          =   312
      Left            =   4200
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   7560
      Width           =   1692
   End
   Begin VB.CommandButton cmdOrdenarContrato 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Ordenar por Contrato"
      Height          =   312
      Left            =   2520
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   7560
      Width           =   1692
   End
   Begin VB.CommandButton cmdCerrarReporte 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Cerrar Reporte"
      Height          =   312
      Left            =   8760
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   7560
      Width           =   1212
   End
   Begin VB.CommandButton cmdReportes 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Reportes"
      Default         =   -1  'True
      Height          =   312
      Left            =   7560
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   7560
      Width           =   1212
   End
   Begin VB.CommandButton cmdSalir 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Salir"
      Height          =   312
      Left            =   9960
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   7560
      Width           =   1212
   End
   Begin MSComctlLib.ListView ListadoVentasCaidas 
      Height          =   6735
      Left            =   120
      TabIndex        =   6
      Top             =   600
      Width           =   10935
      _ExtentX        =   19288
      _ExtentY        =   11880
      SortKey         =   1
      View            =   3
      Sorted          =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      AllowReorder    =   -1  'True
      Checkboxes      =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   16777215
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   8
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Unidad"
         Object.Width           =   1411
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Contrato"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Valor"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Prima Contrato"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Text            =   "Ucp"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Text            =   "Plazo"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   6
         Text            =   "Fecha"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   7
         Text            =   "Ruta"
         Object.Width           =   882
      EndProperty
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Ventas Caidas "
      BeginProperty Font 
         Name            =   "Georgia"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00800000&
      Height          =   375
      Left            =   120
      TabIndex        =   7
      Top             =   120
      Width           =   2295
   End
End
Attribute VB_Name = "frmVentasCaidasCobros"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Cerrado  As String
Private Sub Command1_Click()

End Sub

Private Sub cmdCerrarReporte_Click()
    On Error Resume Next
    
    
    frmCobrosFechaPlanilla.Show 1

    Cerrado = "1"
  '------  ' aqui paso todos los contratos que estan marcados, estos que he pasado son los
    '------------- que se descontaran en planilla

     If ListadoVentasCaidas.ListItems.Count > 0 Then
        For i = 1 To ListadoVentasCaidas.ListItems.Count
            If ListadoVentasCaidas.ListItems(i).Checked Then
                   DE.Cnn.Execute "INSERT  VentasCaidas_Principal (CodigoContrato, Estatus) VALUES  ('" + ListadoVentasCaidas.ListItems(i).ListSubItems(1).Text + "'" + "," + "'P" + "')"
            End If
        Next i
    End If

    ''------------- AHORA BORRO LOS MARCADOS DE VentasCaidas_Temp
      If ListadoVentasCaidas.ListItems.Count > 0 Then
        For i = 1 To ListadoVentasCaidas.ListItems.Count
            If ListadoVentasCaidas.ListItems(i).Checked Then
                   DE.Cnn.Execute "DELETE VentasCaidas_Temp WHERE CodigoContrato = '" + ListadoVentasCaidas.ListItems(i).ListSubItems(1).Text + "'"
            End If
        Next i
    End If

''
'        '' ************************************************************************************************
        On Error Resume Next
        '-------- aqui paso los anulados, estos no los ve el usuario hasta que se cierra el reporte
        '--------los anulados que se pasaran estan entre el rango de fechas que son igual al rango de las diferidas
        If DE.rsAgruparVtaCaidasAnulados.State = adStateOpen Then DE.rsAgruparVtaCaidasAnulados.Close
        DE.AgruparVtaCaidasAnulados FechaPublica

        For X = 1 To DE.rsAgruparVtaCaidasAnulados.RecordCount
            With DE.rsAgruparVtaCaidasAnulados
                Contrato = .Fields("rEdoCodigo_Contrato")
            End With
            DE.Cnn.Execute "INSERT  VentasCaidas_Principal (CodigoContrato, Estatus) VALUES  ('" + Contrato + "'" + "," + "'P" + "')"
        DE.rsAgruparVtaCaidasAnulados.MoveNext
        Next



   
    Dim valor As Double
    ''*****  HACER LA DISTRIBUCION POR PRODUCTO QUE SE GUARDARA EN LA TABLA QUE SE LLAMA "VentaCaidaProductDetalle"
    If DE.rsAgruparVCaidasDitri.State = adStateOpen Then DE.rsAgruparVCaidasDitri.Close
    DE.AgruparVCaidasDitri
        
        With DE.rsAgruparVCaidasDitri
         For m = 1 To DE.rsAgruparVCaidasDitri.RecordCount
            codigoContrato = Trim(.Fields("codigoContrato"))
            codigoVendedor = Trim(.Fields("codigoVendedor"))
            codigo_producto = Trim(.Fields("codigo_producto"))
            valor = .Fields("valor")
            
            
            ' falta meter la fecha de la planilla
            If DE.rsMVentaCaidaProductDetalle.State = adStateOpen Then DE.rsMVentaCaidaProductDetalle.Close
            DE.MVentaCaidaProductDetalle "I", codigoContrato, codigoVendedor, codigo_producto, FechaPublica, valor
            
            DE.rsAgruparVCaidasDitri.MoveNext
         Next m
       End With
       MsgBox "Operacion Satisfactoria"
 
    
    '' AHORA ACTUALIZO LA VISTA
        LlenarVista
    
    
   
End Sub

Private Sub cmdCerrarReporte_GotFocus()
cmdCerrarReporte.BackColor = 65535
End Sub

Private Sub cmdCerrarReporte_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdCerrarReporte_LostFocus()
cmdCerrarReporte.BackColor = 16777215
End Sub

Private Sub cmdMarcar_GotFocus()
cmdMarcar.BackColor = 65535
End Sub

Private Sub cmdMarcar_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdMarcar_LostFocus()
 cmdMarcar.BackColor = 16777215
End Sub


Private Sub cmdOrdenarContrato_Click()
        ListadoVentasCaidas.SortKey = 2
End Sub

Private Sub cmdOrdenarContrato_GotFocus()
         cmdOrdenarContrato.BackColor = 65535
End Sub

Private Sub cmdOrdenarContrato_KeyDown(KeyCode As Integer, Shift As Integer)
 HacerTab KeyCode
End Sub

Private Sub cmdOrdenarContrato_LostFocus()
        cmdOrdenarContrato.BackColor = 16777215

End Sub

Private Sub cmdOrdenarRuta_Click()
        ListadoVentasCaidas.SortKey = 7
End Sub

Private Sub cmdOrdenarRuta_GotFocus()
cmdOrdenarRuta.BackColor = 65535
End Sub

Private Sub cmdOrdenarRuta_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdOrdenarRuta_LostFocus()
        cmdOrdenarRuta.BackColor = 16777215
End Sub

Private Sub cmdOrdenarUnidad_Click()
        ListadoVentasCaidas.SortKey = 0
End Sub

Private Sub cmdOrdenarUnidad_GotFocus()
         cmdOrdenarUnidad.BackColor = 65535
End Sub

Private Sub cmdOrdenarUnidad_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdOrdenarUnidad_LostFocus()
        cmdOrdenarUnidad.BackColor = 16777215
End Sub

Private Sub cmdReportes_Click()
    Dim rsBVentasTemp  As ADODB.Recordset
    Set rsBVentasTemp = New ADODB.Recordset
    rsBVentasTemp.Open "delete from VentasCaidas_Temp", DE.Cnn, adOpenDynamic, adLockReadOnly
    
        
 If ListadoVentasCaidas.ListItems.Count > 0 Then
        For i = 1 To ListadoVentasCaidas.ListItems.Count
            If ListadoVentasCaidas.ListItems(i).Checked Then
                DE.Cnn.Execute "INSERT  VentasCaidas_Temp VALUES  ('" + ListadoVentasCaidas.ListItems(i).ListSubItems(1).Text + "')"
            End If
        Next i
    End If
    frmReportVC.Show 1
   
End Sub

Private Sub cmdReportes_GotFocus()
cmdReportes.BackColor = 65535
End Sub

Private Sub cmdReportes_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdReportes_LostFocus()
        cmdReportes.BackColor = 16777215
End Sub

Private Sub cmdSalir_Click()

    On Error Resume Next
    
    '' aqui meto los marcados
    Dim rsBorrarVentasTemp  As ADODB.Recordset
    Set rsBorrarVentasTemp = New ADODB.Recordset
    rsBorrarVentasTemp.Open "delete from VentasCaidas_Temp", DE.Cnn, adOpenDynamic, adLockReadOnly
     
     
 If ListadoVentasCaidas.ListItems.Count > 0 Then
        For i = 1 To ListadoVentasCaidas.ListItems.Count
            If ListadoVentasCaidas.ListItems(i).Checked Then
                DE.Cnn.Execute "INSERT  VentasCaidas_Temp VALUES  ('" + ListadoVentasCaidas.ListItems(i).ListSubItems(1).Text + "')"
            End If
        Next i
    End If
 
 

        Unload Me
End Sub

Private Sub cmdSalir_GotFocus()
CmdSalir.BackColor = 65535
End Sub

Private Sub cmdSalir_KeyDown(KeyCode As Integer, Shift As Integer)
    HacerTab KeyCode
End Sub

Private Sub cmdSalir_LostFocus()
CmdSalir.BackColor = 16777215
End Sub

Private Sub Form_Load()
    Left = Screen.Width / 2 - Width / 2
    Top = (Screen.Height / 2 - Height / 2) - 800
   ' Me.Picture = LoadResPicture(104, 0)
    LlenarVista
    Cerrado = "0"
    If Cerrado = "0" Then cmdReportes.Enabled = True
   

End Sub
Private Sub LlenarVista()
' On Error Resume Next

    Dim dTotal As Double
    Dim itm As ListItem
    Dim I_contador As Integer
  
    I_contador = 0
    dTotal = 0
    
    
    Me.ListadoVentasCaidas.ListItems.Clear
    
    If DE.rsAgruparVentasCaidasCobros.State = adStateOpen Then DE.rsAgruparVentasCaidasCobros.Close
    DE.AgruparVentasCaidasCobros
    
    '' esta es la consulta para ver todos los que estan como prospectos
    
    While Not DE.rsAgruparVentasCaidasCobros.EOF
       Set itm = Me.ListadoVentasCaidas.ListItems.Add(, , DE.rsAgruparVentasCaidasCobros.Fields("Codigo_Division_Venta").Value)
            itm.SubItems(1) = DE.rsAgruparVentasCaidasCobros.Fields("rEdoCodigo_Contrato").Value
            itm.SubItems(2) = DE.rsAgruparVentasCaidasCobros.Fields("Valor_Contrato").Value
            itm.SubItems(3) = DE.rsAgruparVentasCaidasCobros.Fields("Prima_Contrato").Value
            itm.SubItems(4) = DE.rsAgruparVentasCaidasCobros.Fields("iUcp").Value
            itm.SubItems(5) = DE.rsAgruparVentasCaidasCobros.Fields("iPlazo").Value
            itm.SubItems(6) = DE.rsAgruparVentasCaidasCobros.Fields("Fecha_de_Venta").Value
            itm.SubItems(7) = DE.rsAgruparVentasCaidasCobros.Fields("Rut_Codigo").Value
            If Not IsNull(DE.rsAgruparVentasCaidasCobros.Fields("EXISTE").Value) Then
                Me.ListadoVentasCaidas.ListItems(Me.ListadoVentasCaidas.ListItems.Count).Checked = True
            End If
            DE.rsAgruparVentasCaidasCobros.MoveNext
            
       
            
     Wend

  End Sub

